package com.grass.p019lv.novel.adapter;

import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.androidsa.bttsddka.R;
import com.androidx.p013lv.base.BaseSdk;
import com.androidx.p013lv.base.glide.GlideUtils;
import com.androidx.p013lv.base.recycler.BaseRecyclerAdapter;
import com.androidx.p013lv.base.recycler.BaseRecyclerHolder;
import com.androidx.p013lv.base.utils.ButtonUtil;
import com.androidx.p013lv.base.utils.SpUtils;
import com.androidx.p013lv.base.utils.TimeUtils;
import com.androidx.p013lv.base.utils.UiUtils;
import com.androidx.p013lv.base.view.CircleImageView;
import com.grass.p019lv.bean.NovelCommentBean;
import com.grass.p019lv.novel.fragment.NovelCommentHttpUtils;
import com.grass.p019lv.novel.fragment.NovelCommentVerticalLayout;
import com.like.LikeButton;
import com.like.OnLikeListener;
import java.util.ArrayList;
import java.util.List;

/* renamed from: com.grass.lv.novel.adapter.NovelCommentAdapter */
public class NovelCommentAdapter extends BaseRecyclerAdapter<NovelCommentBean, Holder> {
    private String imgDomain = "";
    private boolean isItemRefresh;
    private NovelCommentVerticalLayout.OnTwoClickListener onTwoClickListener;
    private int userId;

    public void setItemRefresh(boolean z) {
        this.isItemRefresh = z;
    }

    public void setOnTwoClickListener(NovelCommentVerticalLayout.OnTwoClickListener onTwoClickListener2) {
        this.onTwoClickListener = onTwoClickListener2;
    }

    public void setImgDomain(String str) {
        if (!TextUtils.isEmpty(str) && TextUtils.isEmpty(this.imgDomain)) {
            this.imgDomain = str;
        }
    }

    public void setUserId(int i) {
        this.userId = i;
    }

    public void MyHolder(Holder holder, int i) {
        holder.setData((NovelCommentBean) getDataInPosition(i));
    }

    @Override // androidx.recyclerview.widget.RecyclerView.Adapter
    public Holder onCreateViewHolder(ViewGroup viewGroup, int i) {
        return new Holder(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.novel_comment_item, viewGroup, false));
    }

    /* access modifiers changed from: package-private */
    /* renamed from: com.grass.lv.novel.adapter.NovelCommentAdapter$Holder */
    public class Holder extends BaseRecyclerHolder {
        LikeButton bt_isLike;
        LinearLayout expansion_btn;
        TextView expansion_num_txt;
        CircleImageView imageView;
        ImageView iv_vip;
        NovelCommentVerticalLayout layout_comment2;
        TextView tv_author;
        TextView tv_city;
        TextView tv_content;
        TextView tv_like_num;
        TextView tv_name;
        TextView tv_time;

        private Holder(View view) {
            super(view);
            this.imageView = (CircleImageView) view.findViewById(R.id.img_head);
            this.layout_comment2 = (NovelCommentVerticalLayout) view.findViewById(R.id.layout_comment2);
            if (NovelCommentAdapter.this.onTwoClickListener != null) {
                this.layout_comment2.setOnTwoClickListener(NovelCommentAdapter.this.onTwoClickListener);
            }
            this.tv_name = (TextView) view.findViewById(R.id.tv_name);
            this.tv_author = (TextView) view.findViewById(R.id.tv_author);
            this.tv_content = (TextView) view.findViewById(R.id.tv_content);
            this.tv_time = (TextView) view.findViewById(R.id.tv_time);
            this.bt_isLike = (LikeButton) view.findViewById(R.id.bt_isLike);
            this.tv_like_num = (TextView) view.findViewById(R.id.tv_like_num);
            this.expansion_btn = (LinearLayout) view.findViewById(R.id.expansion_btn);
            this.expansion_num_txt = (TextView) view.findViewById(R.id.expansion_num_txt);
            this.iv_vip = (ImageView) view.findViewById(R.id.iv_vip);
            this.tv_city = (TextView) view.findViewById(R.id.tv_city);
        }

        public void setData(final NovelCommentBean novelCommentBean) {
            GlideUtils.loadPicHead(NovelCommentAdapter.this.imgDomain + novelCommentBean.getUserLogo(), this.imageView);
            this.layout_comment2.setUserId(NovelCommentAdapter.this.userId);
            this.layout_comment2.setParentId(novelCommentBean.getId());
            boolean z = false;
            if (NovelCommentAdapter.this.isItemRefresh) {
                if (novelCommentBean.getReply() != null) {
                    this.layout_comment2.setVisibility(0);
                    this.layout_comment2.addCommentsWithLimit(novelCommentBean.getReply(), novelCommentBean.getReply().size(), false);
                } else {
                    this.layout_comment2.setVisibility(8);
                }
            } else if (novelCommentBean.getReply() != null) {
                this.layout_comment2.setVisibility(0);
                this.layout_comment2.addCommentsWithLimit(novelCommentBean.getReply(), 1, false);
                if (novelCommentBean.getReply().size() != 1) {
                    this.expansion_btn.setVisibility(0);
                    TextView textView = this.expansion_num_txt;
                    textView.setText(String.valueOf("展開" + novelCommentBean.getReply().size() + "條回復"));
                    this.expansion_btn.setOnClickListener(new View.OnClickListener() {
                        /* class com.grass.p019lv.novel.adapter.NovelCommentAdapter.Holder.View$OnClickListenerC31421 */

                        public void onClick(View view) {
                            Holder.this.expansion_btn.setVisibility(8);
                            Holder.this.layout_comment2.addCommentsWithLimit(novelCommentBean.getReply(), novelCommentBean.getReply().size(), false);
                        }
                    });
                }
            } else {
                this.layout_comment2.setVisibility(8);
                this.expansion_btn.setVisibility(8);
            }
            this.tv_name.setText(novelCommentBean.getUserNickName());
            if (NovelCommentAdapter.this.userId == novelCommentBean.getUserId()) {
                this.tv_author.setVisibility(0);
            } else {
                this.tv_author.setVisibility(8);
            }
            this.tv_content.setText(novelCommentBean.getContent());
            this.tv_time.setText(TimeUtils.utc2Common(novelCommentBean.getCreatedAt()));
            this.tv_like_num.setText(UiUtils.num2str(novelCommentBean.getLikeNum()));
            final int userId = SpUtils.getInstance().getUserInfo().getUserId();
            if (novelCommentBean.getLikeUserIds() != null) {
                z = novelCommentBean.getLikeUserIds().contains(Integer.valueOf(userId));
            }
            if (z) {
                this.tv_like_num.setTextColor(BaseSdk.getContext().getResources().getColor(R.color.E24339));
            } else {
                this.tv_like_num.setTextColor(BaseSdk.getContext().getResources().getColor(R.color.white));
            }
            this.bt_isLike.setLiked(Boolean.valueOf(z));
            this.bt_isLike.setOnLikeListener(new OnLikeListener() {
                /* class com.grass.p019lv.novel.adapter.NovelCommentAdapter.Holder.C31432 */

                @Override // com.like.OnLikeListener
                public void liked(LikeButton likeButton) {
                    if (ButtonUtil.isFastDoubleClick(1000)) {
                        likeButton.setLiked(false);
                        return;
                    }
                    List<Integer> likeUserIds = novelCommentBean.getLikeUserIds();
                    if (likeUserIds == null) {
                        likeUserIds = new ArrayList<>();
                    }
                    likeUserIds.add(Integer.valueOf(userId));
                    novelCommentBean.setLikeUserIds(likeUserIds);
                    NovelCommentHttpUtils.commentLike(novelCommentBean);
                    NovelCommentBean novelCommentBean = novelCommentBean;
                    novelCommentBean.setLikeNum(novelCommentBean.getLikeNum() + 1);
                    Holder.this.tv_like_num.setTextColor(BaseSdk.getContext().getResources().getColor(R.color.E24339));
                    Holder.this.tv_like_num.setText(UiUtils.num2str(novelCommentBean.getLikeNum()));
                }

                @Override // com.like.OnLikeListener
                public void unLiked(LikeButton likeButton) {
                    if (ButtonUtil.isFastDoubleClick(1000)) {
                        likeButton.setLiked(true);
                        return;
                    }
                    if (novelCommentBean.getLikeNum() >= 1) {
                        NovelCommentBean novelCommentBean = novelCommentBean;
                        novelCommentBean.setLikeNum(novelCommentBean.getLikeNum() - 1);
                    }
                    List<Integer> likeUserIds = novelCommentBean.getLikeUserIds();
                    if (likeUserIds != null) {
                        for (int i = 0; i < likeUserIds.size(); i++) {
                            if (userId == likeUserIds.get(i).intValue()) {
                                likeUserIds.remove(i);
                            }
                        }
                    }
                    Holder.this.tv_like_num.setTextColor(BaseSdk.getContext().getResources().getColor(R.color.white));
                    Holder.this.tv_like_num.setText(UiUtils.num2str(novelCommentBean.getLikeNum()));
                    NovelCommentHttpUtils.commentUnlike(novelCommentBean);
                }
            });
        }
    }
}
